public class BookModule extends Module {
public Stack<Choicepoint> tryToContinue(Compound term, int choice, Stack<Choicepoint> choicepoints, Unifier unifier) {
int nextHeight = choicepoints.height+1;
Stack<Conjunct> query = choicepoints.head.query.tail;
if(term.arity == 0 && term.name.equals("true")) {
if(choice == 1) {
final Term t1 = new Compound("true");
if(unifier.unify(term,t1)) {
status = Module.Status.Success;
return new Stack<Choicepoint>(new Choicepoint(query,unifier.bound,false),choicepoints);
}
else {
status = Module.Status.TryAgain;
return choicepoints;
}
}
status = Module.Status.ThatsAll;
return choicepoints;
}
if(term.arity == 1 && term.name.equals("flip")) {
if(choice == 1) {
final Term t2 = new Compound("heads");
final Term t1 = new Compound("flip", t2);
if(unifier.unify(term,t1)) {
status = Module.Status.Success;
return new Stack<Choicepoint>(new Choicepoint(query,unifier.bound,false),choicepoints);
}
else {
status = Module.Status.TryAgain;
return choicepoints;
}
}
else if(choice == 2) {
final Term t2 = new Compound("tails");
final Term t1 = new Compound("flip", t2);
if(unifier.unify(term,t1)) {
status = Module.Status.Success;
return new Stack<Choicepoint>(new Choicepoint(query,unifier.bound,false),choicepoints);
}
else {
status = Module.Status.TryAgain;
return choicepoints;
}
}
status = Module.Status.ThatsAll;
return choicepoints;
}
if(term.arity == 2 && term.name.equals("=")) {
if(choice == 1) {
final Term t2 = new Variable();
final Term t1 = new Compound("=", t2, t2);
if(unifier.unify(term,t1)) {
status = Module.Status.Success;
return new Stack<Choicepoint>(new Choicepoint(query,unifier.bound,false),choicepoints);
}
else {
status = Module.Status.TryAgain;
return choicepoints;
}
}
status = Module.Status.ThatsAll;
return choicepoints;
}
if(term.arity == 1 && term.name.equals("call")) {
if(choice == 1) {
final Term t2 = new Variable();
final Term t1 = new Compound("call", t2);
if(unifier.unify(term,t1)) {
status = Module.Status.Success;
query = new Stack<Conjunct>(new Predicate(t2,0,nextHeight),query);
return new Stack<Choicepoint>(new Choicepoint(query,unifier.bound,false),choicepoints);
}
else {
status = Module.Status.TryAgain;
return choicepoints;
}
}
status = Module.Status.ThatsAll;
return choicepoints;
}
if(term.arity == 2 && term.name.equals(",")) {
if(choice == 1) {
final Term t2 = new Variable();
final Term t3 = new Variable();
final Term t1 = new Compound(",", t2, t3);
if(unifier.unify(term,t1)) {
status = Module.Status.Success;
query = new Stack<Conjunct>(new Predicate(t3,0,nextHeight),query);
query = new Stack<Conjunct>(new Predicate(t2,0,nextHeight),query);
return new Stack<Choicepoint>(new Choicepoint(query,unifier.bound,false),choicepoints);
}
else {
status = Module.Status.TryAgain;
return choicepoints;
}
}
status = Module.Status.ThatsAll;
return choicepoints;
}
if(term.arity == 1 && term.name.equals("\\+")) {
if(choice == 1) {
final Term t2 = new Variable();
final Term t1 = new Compound("\\+", t2);
if(unifier.unify(term,t1)) {
status = Module.Status.Success;
final Term t3 = new Compound("fail");
query = new Stack<Conjunct>(new Predicate(t3,0,nextHeight),query);
final Term t4 = new Compound("!");
query = new Stack<Conjunct>(new Predicate(t4,0,nextHeight),query);
final Term t5 = new Compound("call", t2);
query = new Stack<Conjunct>(new Predicate(t5,0,nextHeight),query);
return new Stack<Choicepoint>(new Choicepoint(query,unifier.bound,false),choicepoints);
}
else {
status = Module.Status.TryAgain;
return choicepoints;
}
}
else if(choice == 2) {
final Term t2 = new Variable();
final Term t1 = new Compound("\\+", t2);
if(unifier.unify(term,t1)) {
status = Module.Status.Success;
return new Stack<Choicepoint>(new Choicepoint(query,unifier.bound,false),choicepoints);
}
else {
status = Module.Status.TryAgain;
return choicepoints;
}
}
status = Module.Status.ThatsAll;
return choicepoints;
}
if(term.arity == 2 && term.name.equals("\\=")) {
if(choice == 1) {
final Term t2 = new Variable();
final Term t3 = new Variable();
final Term t1 = new Compound("\\=", t2, t3);
if(unifier.unify(term,t1)) {
status = Module.Status.Success;
final Term t5 = new Compound("=", t2, t3);
final Term t4 = new Compound("\\+", t5);
query = new Stack<Conjunct>(new Predicate(t4,0,nextHeight),query);
return new Stack<Choicepoint>(new Choicepoint(query,unifier.bound,false),choicepoints);
}
else {
status = Module.Status.TryAgain;
return choicepoints;
}
}
status = Module.Status.ThatsAll;
return choicepoints;
}
if(term.arity == 2 && term.name.equals("=>")) {
if(choice == 1) {
final Term t2 = new Variable();
final Term t3 = new Variable();
final Term t1 = new Compound("=>", t2, t3);
if(unifier.unify(term,t1)) {
status = Module.Status.Success;
final Term t6 = new Compound("call", t2);
final Term t8 = new Compound("call", t3);
final Term t7 = new Compound("\\+", t8);
final Term t5 = new Compound(",", t6, t7);
final Term t4 = new Compound("\\+", t5);
query = new Stack<Conjunct>(new Predicate(t4,0,nextHeight),query);
return new Stack<Choicepoint>(new Choicepoint(query,unifier.bound,false),choicepoints);
}
else {
status = Module.Status.TryAgain;
return choicepoints;
}
}
status = Module.Status.ThatsAll;
return choicepoints;
}
if(term.arity == 2 && term.name.equals("==")) {
if(choice == 1) {
final Term t2 = new Variable();
final Term t3 = new Variable();
final Term t1 = new Compound("==", t2, t3);
if(unifier.unify(term,t1)) {
status = Module.Status.Success;
final Term t7 = new Compound("chalk");
final Term t6 = new Compound("=", t2, t7);
final Term t9 = new Compound("cheese");
final Term t8 = new Compound("=", t3, t9);
final Term t5 = new Compound(",", t6, t8);
final Term t4 = new Compound("\\+", t5);
query = new Stack<Conjunct>(new Predicate(t4,0,nextHeight),query);
final Term t10 = new Compound("var", t3);
query = new Stack<Conjunct>(new Predicate(t10,0,nextHeight),query);
final Term t11 = new Compound("var", t2);
query = new Stack<Conjunct>(new Predicate(t11,0,nextHeight),query);
return new Stack<Choicepoint>(new Choicepoint(query,unifier.bound,false),choicepoints);
}
else {
status = Module.Status.TryAgain;
return choicepoints;
}
}
else if(choice == 2) {
final Term t2 = new Variable();
final Term t3 = new Variable();
final Term t1 = new Compound("==", t2, t3);
if(unifier.unify(term,t1)) {
status = Module.Status.Success;
final Term t7 = new Variable();
final Term t8 = new Variable();
final Term t6 = new Compound("arg", t7, t2, t8);
final Term t10 = new Variable();
final Term t9 = new Compound("arg", t7, t3, t10);
final Term t5 = new Compound(",", t6, t9);
final Term t11 = new Compound("==", t8, t10);
final Term t4 = new Compound("=>", t5, t11);
query = new Stack<Conjunct>(new Predicate(t4,0,nextHeight),query);
final Term t13 = new Variable();
final Term t14 = new Variable();
final Term t12 = new Compound("functor", t3, t13, t14);
query = new Stack<Conjunct>(new Predicate(t12,0,nextHeight),query);
final Term t15 = new Compound("functor", t2, t13, t14);
query = new Stack<Conjunct>(new Predicate(t15,0,nextHeight),query);
return new Stack<Choicepoint>(new Choicepoint(query,unifier.bound,false),choicepoints);
}
else {
status = Module.Status.TryAgain;
return choicepoints;
}
}
status = Module.Status.ThatsAll;
return choicepoints;
}
if(term.arity == 2 && term.name.equals("member")) {
if(choice == 1) {
final Term t2 = new Variable();
final Term t4 = new Variable();
final Term t3 = new Compound(".", t2, t4);
final Term t1 = new Compound("member", t2, t3);
if(unifier.unify(term,t1)) {
status = Module.Status.Success;
return new Stack<Choicepoint>(new Choicepoint(query,unifier.bound,false),choicepoints);
}
else {
status = Module.Status.TryAgain;
return choicepoints;
}
}
else if(choice == 2) {
final Term t2 = new Variable();
final Term t4 = new Variable();
final Term t5 = new Variable();
final Term t3 = new Compound(".", t4, t5);
final Term t1 = new Compound("member", t2, t3);
if(unifier.unify(term,t1)) {
status = Module.Status.Success;
final Term t6 = new Compound("member", t2, t5);
query = new Stack<Conjunct>(new Predicate(t6,0,nextHeight),query);
return new Stack<Choicepoint>(new Choicepoint(query,unifier.bound,false),choicepoints);
}
else {
status = Module.Status.TryAgain;
return choicepoints;
}
}
status = Module.Status.ThatsAll;
return choicepoints;
}
if(term.arity == 2 && term.name.equals("memq")) {
if(choice == 1) {
final Term t2 = new Variable();
final Term t4 = new Variable();
final Term t5 = new Variable();
final Term t3 = new Compound(".", t4, t5);
final Term t1 = new Compound("memq", t2, t3);
if(unifier.unify(term,t1)) {
status = Module.Status.Success;
final Term t6 = new Compound("==", t2, t4);
query = new Stack<Conjunct>(new Predicate(t6,0,nextHeight),query);
return new Stack<Choicepoint>(new Choicepoint(query,unifier.bound,false),choicepoints);
}
else {
status = Module.Status.TryAgain;
return choicepoints;
}
}
else if(choice == 2) {
final Term t2 = new Variable();
final Term t4 = new Variable();
final Term t5 = new Variable();
final Term t3 = new Compound(".", t4, t5);
final Term t1 = new Compound("memq", t2, t3);
if(unifier.unify(term,t1)) {
status = Module.Status.Success;
final Term t6 = new Compound("memq", t2, t5);
query = new Stack<Conjunct>(new Predicate(t6,0,nextHeight),query);
return new Stack<Choicepoint>(new Choicepoint(query,unifier.bound,false),choicepoints);
}
else {
status = Module.Status.TryAgain;
return choicepoints;
}
}
status = Module.Status.ThatsAll;
return choicepoints;
}
if(term.arity == 3 && term.name.equals("append")) {
if(choice == 1) {
final Term t2 = new Compound("[]");
final Term t3 = new Variable();
final Term t1 = new Compound("append", t2, t3, t3);
if(unifier.unify(term,t1)) {
status = Module.Status.Success;
return new Stack<Choicepoint>(new Choicepoint(query,unifier.bound,false),choicepoints);
}
else {
status = Module.Status.TryAgain;
return choicepoints;
}
}
else if(choice == 2) {
final Term t3 = new Variable();
final Term t4 = new Variable();
final Term t2 = new Compound(".", t3, t4);
final Term t5 = new Variable();
final Term t7 = new Variable();
final Term t6 = new Compound(".", t3, t7);
final Term t1 = new Compound("append", t2, t5, t6);
if(unifier.unify(term,t1)) {
status = Module.Status.Success;
final Term t8 = new Compound("append", t4, t5, t7);
query = new Stack<Conjunct>(new Predicate(t8,0,nextHeight),query);
return new Stack<Choicepoint>(new Choicepoint(query,unifier.bound,false),choicepoints);
}
else {
status = Module.Status.TryAgain;
return choicepoints;
}
}
status = Module.Status.ThatsAll;
return choicepoints;
}
if(term.arity == 3 && term.name.equals("split")) {
if(choice == 1) {
final Term t3 = new Variable();
final Term t4 = new Variable();
final Term t2 = new Compound(".", t3, t4);
final Term t6 = new Compound("[]");
final Term t5 = new Compound("-", t6, t4);
final Term t1 = new Compound("split", t2, t3, t5);
if(unifier.unify(term,t1)) {
status = Module.Status.Success;
return new Stack<Choicepoint>(new Choicepoint(query,unifier.bound,false),choicepoints);
}
else {
status = Module.Status.TryAgain;
return choicepoints;
}
}
else if(choice == 2) {
final Term t3 = new Variable();
final Term t4 = new Variable();
final Term t2 = new Compound(".", t3, t4);
final Term t5 = new Variable();
final Term t8 = new Variable();
final Term t7 = new Compound(".", t3, t8);
final Term t9 = new Variable();
final Term t6 = new Compound("-", t7, t9);
final Term t1 = new Compound("split", t2, t5, t6);
if(unifier.unify(term,t1)) {
status = Module.Status.Success;
final Term t11 = new Compound("-", t8, t9);
final Term t10 = new Compound("split", t4, t5, t11);
query = new Stack<Conjunct>(new Predicate(t10,0,nextHeight),query);
return new Stack<Choicepoint>(new Choicepoint(query,unifier.bound,false),choicepoints);
}
else {
status = Module.Status.TryAgain;
return choicepoints;
}
}
status = Module.Status.ThatsAll;
return choicepoints;
}
if(term.arity == 3 && term.name.equals("sort")) {
if(choice == 1) {
final Term t2 = new Variable();
final Term t3 = new Variable();
final Term t4 = new Variable();
final Term t1 = new Compound("sort", t2, t3, t4);
if(unifier.unify(term,t1)) {
status = Module.Status.Success;
final Term t6 = new Compound("[]");
final Term t5 = new Compound("qsort", t2, t3, t4, t6);
query = new Stack<Conjunct>(new Predicate(t5,0,nextHeight),query);
return new Stack<Choicepoint>(new Choicepoint(query,unifier.bound,false),choicepoints);
}
else {
status = Module.Status.TryAgain;
return choicepoints;
}
}
status = Module.Status.ThatsAll;
return choicepoints;
}
if(term.arity == 4 && term.name.equals("qsort")) {
if(choice == 1) {
final Term t2 = new Variable();
final Term t4 = new Variable();
final Term t5 = new Variable();
final Term t3 = new Compound(".", t4, t5);
final Term t6 = new Variable();
final Term t7 = new Variable();
final Term t1 = new Compound("qsort", t2, t3, t6, t7);
if(unifier.unify(term,t1)) {
status = Module.Status.Success;
final Term t9 = new Variable();
final Term t11 = new Variable();
final Term t10 = new Compound(".", t4, t11);
final Term t8 = new Compound("qsort", t2, t9, t6, t10);
query = new Stack<Conjunct>(new Predicate(t8,0,nextHeight),query);
final Term t13 = new Variable();
final Term t12 = new Compound("qsort", t2, t13, t11, t7);
query = new Stack<Conjunct>(new Predicate(t12,0,nextHeight),query);
final Term t14 = new Compound("partition", t2, t5, t4, t9, t13);
query = new Stack<Conjunct>(new Predicate(t14,0,nextHeight),query);
return new Stack<Choicepoint>(new Choicepoint(query,unifier.bound,false),choicepoints);
}
else {
status = Module.Status.TryAgain;
return choicepoints;
}
}
else if(choice == 2) {
final Term t2 = new Variable();
final Term t3 = new Compound("[]");
final Term t4 = new Variable();
final Term t1 = new Compound("qsort", t2, t3, t4, t4);
if(unifier.unify(term,t1)) {
status = Module.Status.Success;
return new Stack<Choicepoint>(new Choicepoint(query,unifier.bound,false),choicepoints);
}
else {
status = Module.Status.TryAgain;
return choicepoints;
}
}
status = Module.Status.ThatsAll;
return choicepoints;
}
if(term.arity == 5 && term.name.equals("partition")) {
if(choice == 1) {
final Term t2 = new Variable();
final Term t4 = new Variable();
final Term t5 = new Variable();
final Term t3 = new Compound(".", t4, t5);
final Term t6 = new Variable();
final Term t8 = new Variable();
final Term t7 = new Compound(".", t4, t8);
final Term t9 = new Variable();
final Term t1 = new Compound("partition", t2, t3, t6, t7, t9);
if(unifier.unify(term,t1)) {
status = Module.Status.Success;
final Term t10 = new Compound("partition", t2, t5, t6, t8, t9);
query = new Stack<Conjunct>(new Predicate(t10,0,nextHeight),query);
final Term t11 = new Compound("!");
query = new Stack<Conjunct>(new Predicate(t11,0,nextHeight),query);
final Term t13 = new Variable();
final Term t14 = new Variable();
final Term t12 = new Compound(">=", t13, t14);
query = new Stack<Conjunct>(new Predicate(t12,0,nextHeight),query);
final Term t18 = new Compound("[]");
final Term t17 = new Compound(".", t14, t18);
final Term t16 = new Compound(".", t6, t17);
final Term t15 = new Compound("apply", t2, t16);
query = new Stack<Conjunct>(new Predicate(t15,0,nextHeight),query);
final Term t22 = new Compound("[]");
final Term t21 = new Compound(".", t13, t22);
final Term t20 = new Compound(".", t4, t21);
final Term t19 = new Compound("apply", t2, t20);
query = new Stack<Conjunct>(new Predicate(t19,0,nextHeight),query);
return new Stack<Choicepoint>(new Choicepoint(query,unifier.bound,false),choicepoints);
}
else {
status = Module.Status.TryAgain;
return choicepoints;
}
}
else if(choice == 2) {
final Term t2 = new Variable();
final Term t4 = new Variable();
final Term t5 = new Variable();
final Term t3 = new Compound(".", t4, t5);
final Term t6 = new Variable();
final Term t7 = new Variable();
final Term t9 = new Variable();
final Term t8 = new Compound(".", t4, t9);
final Term t1 = new Compound("partition", t2, t3, t6, t7, t8);
if(unifier.unify(term,t1)) {
status = Module.Status.Success;
final Term t10 = new Compound("partition", t2, t5, t6, t7, t9);
query = new Stack<Conjunct>(new Predicate(t10,0,nextHeight),query);
return new Stack<Choicepoint>(new Choicepoint(query,unifier.bound,false),choicepoints);
}
else {
status = Module.Status.TryAgain;
return choicepoints;
}
}
else if(choice == 3) {
final Term t2 = new Variable();
final Term t3 = new Compound("[]");
final Term t4 = new Compound("[]");
final Term t5 = new Compound("[]");
final Term t1 = new Compound("partition", t2, t3, t2, t4, t5);
if(unifier.unify(term,t1)) {
status = Module.Status.Success;
return new Stack<Choicepoint>(new Choicepoint(query,unifier.bound,false),choicepoints);
}
else {
status = Module.Status.TryAgain;
return choicepoints;
}
}
status = Module.Status.ThatsAll;
return choicepoints;
}
if(term.arity == 2 && term.name.equals("$foo$expand_term")) {
if(choice == 1) {
final Term t2 = new Variable();
final Term t3 = new Variable();
final Term t1 = new Compound("$foo$expand_term", t2, t3);
if(unifier.unify(term,t1)) {
status = Module.Status.Success;
final Term t4 = new Compound("!");
query = new Stack<Conjunct>(new Predicate(t4,0,nextHeight),query);
final Term t5 = new Compound("$foo$term_expansion", t2, t3);
query = new Stack<Conjunct>(new Predicate(t5,0,nextHeight),query);
return new Stack<Choicepoint>(new Choicepoint(query,unifier.bound,false),choicepoints);
}
else {
status = Module.Status.TryAgain;
return choicepoints;
}
}
else if(choice == 2) {
final Term t2 = new Variable();
final Term t1 = new Compound("$foo$expand_term", t2, t2);
if(unifier.unify(term,t1)) {
status = Module.Status.Success;
return new Stack<Choicepoint>(new Choicepoint(query,unifier.bound,false),choicepoints);
}
else {
status = Module.Status.TryAgain;
return choicepoints;
}
}
status = Module.Status.ThatsAll;
return choicepoints;
}
status = Module.Status.NotFound;
return choicepoints;
}
}
